﻿Public Class frmLogin
    Dim ctx As New QLDBDataContext

    Function CheckUser(ByVal us As String, ByVal pas As String) As Boolean
        Dim v = (From q In ctx.users Where q.UserName = us And q.Pass = pas).Count
        If v = 0 Then
            Return False
        Else
            Return True
        End If
    End Function
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Cursor = Cursors.WaitCursor
        If Trim(txtpas.Text.ToString()) = "" Then
            lbpa.Text = "UserName không được để trông:"
            lbpa.Visible = True
            Return
        Else
            lbpa.Visible = False
        End If
        If Trim(txtpas.Text.ToString()) = "" Then
            lbpa.Text = "Pass word không được để trống"
            lbpa.Visible = True
            Return
        Else
            lbpa.Visible = False
        End If
        If CheckUser(txtus.Text, txtpas.Text) = True Then
            Dim f As New Form1 With {.UserName = txtus.Text}
            Me.Hide()
            Cursor = Cursors.Default
            f.Show()

        Else
            lbpa.Text = "UserName Hoặc PassWord Sai:"
            lbpa.Visible = True
            Cursor = Cursors.Default
        End If
    End Sub
End Class